package com.bishe.app.modules.userSaleIncome.model;

import cn.hutool.core.util.ReflectUtil;
import com.bishe.app.modules.userSaleIncome.service.impl.UserSaleIncomeServiceImpl;
import lombok.Data;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Optional;

/**
 * Created : 2024/3/31, 16:27
 *
 * @author : jeffrey.hu
 **/
@Data
public class UserSaleIncomeDetailModel {
    private String ticheng1;
    private String ticheng2;
    private String ticheng3;
    /**
     * 单人班提成
     */
    private String singleTicheng;
    private String basicSalary;
    private String daiban;
    private String xiuxi;
    private String maibanjiang;
    private String quanqinjiang;
    private String gongling;
    private String chaojiang;
    private String jiarijiang;
    private String baoxianbutie;
    private String pandian;
    private String fakuan;
    private String shifagongzi;

    public UserSaleIncomeDetailModel() {
    }

    public UserSaleIncomeDetailModel(UserSaleIncomeDetailModel saleIncomeDetailModel) {
        this.setSingleTicheng(saleIncomeDetailModel.getSingleTicheng());
        this.setTicheng1(saleIncomeDetailModel.getTicheng1());
        this.setTicheng2(saleIncomeDetailModel.getTicheng2());
        this.setTicheng3(saleIncomeDetailModel.getTicheng3());
        this.setBasicSalary(saleIncomeDetailModel.getBasicSalary());
        this.setDaiban(saleIncomeDetailModel.getDaiban());
        this.setXiuxi(saleIncomeDetailModel.getXiuxi());
        this.setMaibanjiang(saleIncomeDetailModel.getMaibanjiang());
        this.setQuanqinjiang(saleIncomeDetailModel.getQuanqinjiang());
        this.setGongling(saleIncomeDetailModel.getGongling());
        this.setChaojiang(saleIncomeDetailModel.getChaojiang());
        this.setJiarijiang(saleIncomeDetailModel.getJiarijiang());
        this.setBaoxianbutie(saleIncomeDetailModel.getBaoxianbutie());
        this.setPandian(saleIncomeDetailModel.getPandian());
        this.setFakuan(saleIncomeDetailModel.getFakuan());
        this.setShifagongzi(saleIncomeDetailModel.getShifagongzi());
    }



    public static UserSaleIncomeDetailModel init(){
        UserSaleIncomeDetailModel userSaleIncomeDetailModel = new UserSaleIncomeDetailModel();
        userSaleIncomeDetailModel.setSingleTicheng("0");
        userSaleIncomeDetailModel.setTicheng1("0");
        userSaleIncomeDetailModel.setTicheng2("0");
        userSaleIncomeDetailModel.setTicheng3("0");
        userSaleIncomeDetailModel.setBasicSalary("0");
        userSaleIncomeDetailModel.setDaiban("0");
        userSaleIncomeDetailModel.setXiuxi("0");
        userSaleIncomeDetailModel.setMaibanjiang("0");
        userSaleIncomeDetailModel.setQuanqinjiang("0");
        userSaleIncomeDetailModel.setGongling("0");
        userSaleIncomeDetailModel.setChaojiang("0");
        userSaleIncomeDetailModel.setJiarijiang("0");
        userSaleIncomeDetailModel.setBaoxianbutie("0");
        userSaleIncomeDetailModel.setPandian("0");
        userSaleIncomeDetailModel.setFakuan("0");
        userSaleIncomeDetailModel.setShifagongzi("0");

        return userSaleIncomeDetailModel;
    }

    public void reCalcShifagongzi() {
        Field[] fieldsDirectly = ReflectUtil.getFieldsDirectly(UserSaleIncomeDetailModel.class, false);

        Double ythisn = 0.0;
        for (Field field : fieldsDirectly) {
            boolean shifagongzi1 = field.getName().equals("shifagongzi");
            if (shifagongzi1) {
                continue;
            }

            String fieldValue = Optional.ofNullable(ReflectUtil.getFieldValue(this, field)).orElse("0").toString();
            Double calculate = UserSaleIncomeServiceImpl.calculate(fieldValue);
            ythisn += calculate;
        }

        this.shifagongzi = new BigDecimal(ythisn).multiply(new BigDecimal(100)).divide(new BigDecimal(100),2, RoundingMode.HALF_UP) + "";
    }
}
